<?
namespace pmvc;

use PHPUnit_Framework_TestCase;
use Exception;

class ArchiveClassLoaderTest
	extends PHPUnit_Framework_TestCase {

	public function testGetResourcePaths() {
		$cl = new ArchiveClassLoader(__DIR__."/test.tar");
		$paths = $cl->getResourcePaths("", true);
		$this->assertEquals(2, count($paths));
		$paths = $cl->getResourcePaths("", false);
		$this->assertEquals(1, count($paths));
	}

	public function testJar() {
		$cl = new ArchiveClassLoader();
		$cl->addToClassPath(__DIR__."/test.jar");
		$this->assertTrue(file_exists($cl->getResourcePath('CLTest.class.php')));
		$this->assertTrue(file_exists($cl->getResourcePath('deep\CLTestDeep.class.php')));
	}

	//public function testRar() {
	//	$cl = new ArchiveClassLoader();
	//	$cl->addToClassPath(__DIR__."/test.rar");
	//	$this->assertTrue(file_exists($cl->getResourcePath('CLTest.class.php')));
	//	$this->assertTrue(file_exists($cl->getResourcePath('deep\CLTestDeep.class.php')));
	//}

	public function testTar() {
		$cl = new ArchiveClassLoader();
		$cl->addToClassPath(__DIR__."/test.tar");
		$this->assertTrue(file_exists($cl->getResourcePath('CLTest.class.php')));
		$this->assertTrue(file_exists($cl->getResourcePath('deep\CLTestDeep.class.php')));
	}

	public function testTarBz2() {
		$cl = new ArchiveClassLoader();
		$cl->addToClassPath(__DIR__."/test.tar.bz2");
		$this->assertTrue(file_exists($cl->getResourcePath('CLTest.class.php')));
		$this->assertTrue(file_exists($cl->getResourcePath('deep\CLTestDeep.class.php')));
	}

	public function testTarGz() {
		$cl = new ArchiveClassLoader();
		$cl->addToClassPath(__DIR__."/test.tar.gz");
		$this->assertTrue(file_exists($cl->getResourcePath('CLTest.class.php')));
		$this->assertTrue(file_exists($cl->getResourcePath('deep\CLTestDeep.class.php')));
	}

	public function testTgz() {
		$cl = new ArchiveClassLoader();
		$cl->addToClassPath(__DIR__."/test.tgz");
		$this->assertTrue(file_exists($cl->getResourcePath('CLTest.class.php')));
		$this->assertTrue(file_exists($cl->getResourcePath('deep\CLTestDeep.class.php')));
	}

	public function testZip() {
		$cl = new ArchiveClassLoader();
		$cl->addToClassPath(__DIR__."/test.zip");
		$this->assertTrue(file_exists($cl->getResourcePath('CLTest.class.php')));
		$this->assertTrue(file_exists($cl->getResourcePath('deep\CLTestDeep.class.php')));
	}



	public function testJarRoot() {
		$cl = new ArchiveClassLoader();
		$cl->addToClassPath(__DIR__."/test.jar", "/deep");
		$this->assertTrue(file_exists($cl->getResourcePath('CLTestDeep.class.php')));
	}

	//public function testRarRoot() {
	//	$cl = new ArchiveClassLoader();
	//	$cl->addToClassPath(__DIR__."/test.rar", "/deep");
	//	$this->assertTrue(file_exists($cl->getResourcePath('CLTestDeep.class.php')));
	//}

	public function testTarRoot() {
		$cl = new ArchiveClassLoader();
		$cl->addToClassPath(__DIR__."/test.tar", "/deep");
		$this->assertTrue(file_exists($cl->getResourcePath('CLTestDeep.class.php')));
	}

	public function testTarBz2Root() {
		$cl = new ArchiveClassLoader();
		$cl->addToClassPath(__DIR__."/test.tar.bz2", "/deep");
		$this->assertTrue(file_exists($cl->getResourcePath('CLTestDeep.class.php')));
	}

	public function testTarGzRoot() {
		$cl = new ArchiveClassLoader();
		$cl->addToClassPath(__DIR__."/test.tar.gz", "/deep");
		$this->assertTrue(file_exists($cl->getResourcePath('CLTestDeep.class.php')));
	}

	public function testTgzRoot() {
		$cl = new ArchiveClassLoader();
		$cl->addToClassPath(__DIR__."/test.tgz", "/deep");
		$this->assertTrue(file_exists($cl->getResourcePath('CLTestDeep.class.php')));
	}

	public function testZipRoot() {
		$cl = new ArchiveClassLoader();
		$cl->addToClassPath(__DIR__."/test.zip", "/deep");
		$this->assertTrue(file_exists($cl->getResourcePath('CLTestDeep.class.php')));
	}

	
	public function testZipAUTO_ROOTS() {
		$cl = new ArchiveClassLoader();
		$cl->addToClassPath(__DIR__."/testAUTO_ROOTS.zip");
		$this->assertTrue(file_exists($cl->getResourcePath('CLTestDeep.class.php')));
		$this->assertTrue(file_exists($cl->getResourcePath('CLTest.class.php')));
		$this->assertTrue(file_exists($cl->getResourcePath('deep\CLTestDeep.class.php')));
	}
}

?>